package com.health.controller;

import com.health.config.AliyunOssClient;
import com.health.domain.pojo.Setmeal;
import com.health.domain.query.PageQueryDTO;
import com.health.domain.vo.PageBean;
import com.health.domain.vo.Result;
import com.health.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-06-22 08:15
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;
    @Autowired
    private AliyunOssClient ossClient;

    /**
     * 分页条件查询
     * @param pageQueryDTO 分页条件
     * @return
     */
    @PostMapping("/findPage")
    public PageBean<Setmeal> findPage(@RequestBody PageQueryDTO pageQueryDTO) {
        // 处理分页查询
        return setmealService.findPage(pageQueryDTO);
    }

    /**
     * 文件上传
     * @param imgFile 上传文件对象
     * @return 文件在服务器上的路径
     * @throws Exception
     */
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile imgFile) throws Exception {
        String path = ossClient.uploadFile(imgFile.getInputStream(), imgFile.getOriginalFilename());
        return Result.success(path);
    }

    /**
     * 新增
     * @param setmeal 套餐基本信息
     * @param checkgroupIds 检查组ID列表
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody Setmeal setmeal, Integer[] checkgroupIds){
        log.info("setmeal:{}, checkgroupIds:{}", setmeal, checkgroupIds);
        return setmealService.add(setmeal, checkgroupIds);
    }

    @GetMapping("/getAllSetmeal")
    public Result<List<Setmeal>> getAllSetmeal(){
        return setmealService.getAllSetmeal();
    }

    @PostMapping("/findById")
    public Result<Setmeal> findById(Integer id){
        return setmealService.findById(id);
    }

}
